#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int dest, cur;
        for (dest = 0, cur = 0; dest < arr.size(); cur++, dest++)
            if (!arr[cur])
                dest++;
        for (cur = cur - 1, dest = dest - 1; cur >= 0; cur--)
        {
            if (arr[cur])
                arr[dest--] = arr[cur];
            else
            {
                if (dest < arr.size())
                    arr[dest--] = arr[cur];
                else
                    dest--;
                arr[dest--] = arr[cur];
            }
        }
    }
};